﻿
-- =============================================
-- Author:		赵洪涛
-- Create date: 2011-12-08
-- Description:	取相同的客户名称（非自己）
-- =============================================
CREATE PROCEDURE [dbo].[proc_Customer_SearchCusName_NOME]
		@CusName nvarchar(50),
		@UserName nvarchar(50),
		@CustomerId uniqueidentifier
AS
BEGIN
	DECLARE @CompanyId int,@cSql nvarchar(2000)
	Select @CompanyId=CompanyId From Employee Where UserName=@UserName
	
	Set @cSql = 'Select Id,CustomerId,CustomerName,MnemonicWorks,Tel,
	(Select Title From Customer_Protect Where Id=Customer.ProtectId) As Protect,
	(Select EName From Employee Where UserName=Customer.CreateName) As CreateNameEName,
	CreateDate
	From Customer
	Where CompanyId='+Convert(varchar(10),@CompanyId)+' And
	CustomerName Like ''%'+@CusName+'%'' And
	CustomerId<>'''+Convert(varchar(60),@CustomerId)+''''

	Exec(@cSql)
END